cmake_minimum_required (VERSION 2.6)

project (gen2gui)

include_directories(${GEN2LIB_INCLUDE_DIR})

SET(QT_USE_QTMAIN TRUE)

find_package(Qt4 REQUIRED)
include (${QT_USE_FILE})

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

find_package(GraphViz REQUIRED)
include_directories(${graphviz_INCLUDE_DIRECTORIES})
#message(STATUS "graphviz_INCLUDE_DIRECTORIES: " ${graphviz_INCLUDE_DIRECTORIES})

###########################################################################
############ Dialogs
###########################################################################

SET (Dialogs_HEADERS
	src/Dialogs/OptionsDialog.h
)

SET (Dialogs_SOURCES
	src/Dialogs/OptionsDialog.cpp
)

SET (Dialogs_FORMS
	src/Dialogs/OptionsDialog.ui
)

SOURCE_GROUP(Dialogs FILES 
	${Dialogs_HEADERS} 
	${Dialogs_SOURCES}
	${Dialogs_FORMS})

###########################################################################
############ Editors
###########################################################################

SET (Editors_HEADERS
	src/Editors/IModelEditor.h
	src/Editors/TextEditBase.h
)

SET (Editors_SOURCES
	src/Editors/TextEditBase.cpp
)

SOURCE_GROUP(Editors FILES 
	${Editors_HEADERS} 
	${Editors_SOURCES})
	
###########################################################################
############ Editors/CppPreview
###########################################################################

SET (EditorsCppPreview_HEADERS
	src/Editors/CppPreview/CppHighlighter.h
	src/Editors/CppPreview/ModelPreview.h
)

SET (EditorsCppPreview_SOURCES
	src/Editors/CppPreview/CppHighlighter.cpp
	src/Editors/CppPreview/ModelPreview.cpp
)

SOURCE_GROUP(Editors\\CppPreview FILES 
	${EditorsCppPreview_HEADERS} 
	${EditorsCppPreview_SOURCES})

###########################################################################
############ Editors/Gen
###########################################################################

SET (EditorsGen_HEADERS
	src/Editors/Gen/GenEditor.h
	src/Editors/Gen/GenHighlighter.h
)

SET (EditorsGen_SOURCES
	src/Editors/Gen/GenEditor.cpp
	src/Editors/Gen/GenHighlighter.cpp
)

SOURCE_GROUP(Editors\\Gen FILES 
	${EditorsGen_HEADERS} 
	${EditorsGen_SOURCES})
	
###########################################################################
############ Editors/Graph
###########################################################################

SET (EditorsGraph_HEADERS
	src/Editors/Graph/GraphEditor.h
	src/Editors/Graph/GraphScene.h
	src/Editors/Graph/GVGraph.h
)

SET (EditorsGraph_SOURCES
	src/Editors/Graph/GraphEditor.cpp
	src/Editors/Graph/GraphScene.cpp
	src/Editors/Graph/GVGraph.cpp
)

SOURCE_GROUP(Editors\\Graph FILES 
	${EditorsGraph_HEADERS} 
	${EditorsGraph_SOURCES})

###########################################################################
############ GraphicsItems
###########################################################################

SET (GraphicsItems_HEADERS
	src/Editors/Graph/GraphicsItems/Arrow.h
	src/Editors/Graph/GraphicsItems/ClassItem.h
	src/Editors/Graph/GraphicsItems/GraphNodeItem.h
	src/Editors/Graph/GraphicsItems/OperationItem.h
)

SET (GraphicsItems_SOURCES
	src/Editors/Graph/GraphicsItems/Arrow.cpp
	src/Editors/Graph/GraphicsItems/ClassItem.cpp
	src/Editors/Graph/GraphicsItems/GraphNodeItem.cpp
	src/Editors/Graph/GraphicsItems/OperationItem.cpp
)

SOURCE_GROUP(Editors\\Graph\\GraphicsItems FILES 
	${GraphicsItems_HEADERS} 
	${GraphicsItems_SOURCES})
	
###########################################################################
############ Tools
###########################################################################

SET (Tools_HEADERS
	src/Tools/ContextMenuManager.h
	src/Tools/Settings.h
	src/Tools/StringTools.h
)

SET (Tools_SOURCES
	src/Tools/ContextMenuManager.cpp
	src/Tools/Settings.cpp
	src/Tools/StringTools.cpp
)

SOURCE_GROUP(Tools FILES 
	${Tools_HEADERS} 
	${Tools_SOURCES})
	
include_directories(src/Tools)

###########################################################################
############ Main
###########################################################################

SET (Main_HEADERS
	src/MainWindow.h
)

SET (Main_SOURCES
	src/main.cpp
	src/MainWindow.cpp
)

###########################################################################
############ Resources
###########################################################################

SET (RESOURCES
	Resources/Resources.qrc
)
	
IF (WIN32)

    SET (Native_RESOURCES
        Resources/gen2gui.rc
		Resources/gen2gui.ico
    )

else (WIN32)

	SET (Native_RESOURCES
		""
	)
	
endif (WIN32)

SOURCE_GROUP(Resources FILES 
	${RESOURCES} 
	${Native_RESOURCES})
	
###########################################################################
###########################################################################

SET (FORMS
	${Dialogs_FORMS}
)

qt4_wrap_ui(UI_HEADERS ${FORMS})
SOURCE_GROUP(GeneratedFiles\\UI FILES ${UI_HEADERS})
# HACK? Header will be generated in CMAKE_CURRENT_BINARY_DIR
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

SET (HEADERS
	${Dialogs_HEADERS} 
	${Editors_HEADERS} 
	${EditorsCppPreview_HEADERS}
	${EditorsGen_HEADERS}
	${EditorsGraph_HEADERS}
	${GraphicsItems_HEADERS}
	${Tools_HEADERS}
	${Main_HEADERS}
	${UI_HEADERS}
)

qt4_wrap_cpp(MOC_SOURCES ${HEADERS} OPTIONS "-nw")
SOURCE_GROUP(GeneratedFiles\\MOC FILES ${MOC_SOURCES})

qt4_add_resources (QRC_SOURCES ${RESOURCES})
SOURCE_GROUP(GeneratedFiles\\Resources FILES ${QRC_SOURCES})

SET (SOURCES
	${Dialogs_SOURCES}
	${Editors_SOURCES}
	${EditorsCppPreview_SOURCES}
	${EditorsGen_SOURCES}
	${EditorsGraph_SOURCES}
	${GraphicsItems_SOURCES}
	${Tools_SOURCES}
	${Main_SOURCES}
	${MOC_SOURCES}
	${QRC_SOURCES}
	${Native_RESOURCES}
)

add_executable(gen2gui WIN32 ${SOURCES} ${HEADERS})

target_link_libraries(gen2gui gen2lib)
target_link_libraries(gen2gui ${QT_LIBRARIES})
target_link_libraries(gen2gui ${graphviz_LIBRARIES})


IF (WIN32)
	SET (QTLIBS_NAMES QtCore QtGui)
	GET_FILENAME_COMPONENT(QT_DLL_PATH ${QT_QMAKE_EXECUTABLE} PATH)

	FOREACH (QTLIB_NAME ${QTLIBS_NAMES})
		list(APPEND QTLIBS_PATHS_DEBUG ${QT_DLL_PATH}/${QTLIB_NAME}d4.dll)
		list(APPEND QTLIBS_PATHS_DEBUG ${QT_DLL_PATH}/${QTLIB_NAME}d4.pdb)
		list(APPEND QTLIBS_PATHS_RELEASE ${QT_DLL_PATH}/${QTLIB_NAME}4.dll)	
	ENDFOREACH (QTLIB_NAME ${QTLIBS_NAMES})
	 
	INSTALL(FILES ${QTLIBS_PATHS_DEBUG}
		DESTINATION ${CMAKE_BINARY_DIR}/Debug/
		COMPONENT Runtime
		CONFIGURATIONS Debug)
		
	INSTALL(FILES ${QTLIBS_PATHS_RELEASE}
		DESTINATION ${CMAKE_BINARY_DIR}/Release/
		COMPONENT Runtime
		CONFIGURATIONS Release)
ENDIF (WIN32)